package com.txunda.zhuohired.adapter.user.find;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.user.find.FindBean;

import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/6 13:44
 * 功能描述：发现adapter
 * 联系方式：jiahuanchen@126.com
 */

public class FindInformationAdapter extends BaseAdapter {
    private Context context;
    private ViewHolder holder;
    private List<FindBean.DataBean.ArticleBean> articleList;

    public FindInformationAdapter(Context context, List<FindBean.DataBean.ArticleBean> articleList) {
        this.context = context;
        this.articleList = articleList;
    }

    @Override
    public int getCount() {
        return articleList.size();
    }

    @Override
    public Object getItem(int i) {
        return articleList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_find_information, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(articleList.get(i).getPic()).error(R.mipmap.icon_defult).placeholder(R.mipmap
                .icon_defult).dontAnimate().into(holder.iv_item_find);
        if (TextUtils.isEmpty(articleList.get(i).getTitle())) {
            holder.tv_item_find_tittle.setVisibility(View.GONE);
        } else {
            holder.tv_item_find_tittle.setVisibility(View.VISIBLE);
            holder.tv_item_find_tittle.setText(articleList.get(i).getTitle());
        }
        if(TextUtils.isEmpty(articleList.get(i).getType_name())){
            holder.tv_item_find_left.setVisibility(View.GONE);
        }else{
            holder.tv_item_find_left.setVisibility(View.VISIBLE);
            holder.tv_item_find_left.setText(articleList.get(i).getType_name());
        }
        if(TextUtils.isEmpty(articleList.get(i).getView())){
            holder.tv_item_find_look.setVisibility(View.GONE);
        }else{
            holder.tv_item_find_look.setVisibility(View.VISIBLE);
            holder.tv_item_find_look.setText(articleList.get(i).getView());
        }
        if(TextUtils.isEmpty(articleList.get(i).getGoods())){
            holder.tv_item_find_praise.setVisibility(View.GONE);
        }else{
            holder.tv_item_find_praise.setVisibility(View.VISIBLE);
            holder.tv_item_find_praise.setText(articleList.get(i).getGoods());
        }
        return view;
    }

    class ViewHolder {
        @ViewInject(R.id.iv_item_find)
        private ImageView iv_item_find;
        /**
         * 标题
         */
        @ViewInject(R.id.tv_item_find_tittle)
        private TextView tv_item_find_tittle;
        /**
         * 类别
         */
        @ViewInject(R.id.tv_item_find_left)
        private TextView tv_item_find_left;
        /**
         * 围观
         */
        @ViewInject(R.id.tv_item_find_look)
        private TextView tv_item_find_look;
        /**
         * 点赞
         */
        @ViewInject(R.id.tv_item_find_praise)
        private TextView tv_item_find_praise;
    }
}
